package com.lb.bs.client.util;

import com.lb.bs.client.repository.StoreCenter;

/**
 * program: LB-BS-Client
 * author: bsworld.xie
 * create: 2019-12-18 16:12
 * description:
 */
public class KeyGenerateUtil {
    public static final String spliceGrayIPKey(String groupName) {

        return groupName + StoreCenter.GRAY_PREFIX + StoreCenter.GRAY_IP;
    }


    public static final String spliceGrayItemKey(String itemKey) {

        return itemKey + StoreCenter.GRAY_PREFIX;
    }

    /**
     * 生成itemKey
     */
    public static final String spliceItemKey(String groupName, String fieldAnnotationKey) {

        return groupName + fieldAnnotationKey;
    }

    public static final String getItemKeyByGrayItemKey(String grayItemKey) {


        if (grayItemKey == null) {
            return null;
        }

        int index = grayItemKey.lastIndexOf(StoreCenter.GRAY_PREFIX);
        if (index == -1) {
            return grayItemKey;
        }
        return grayItemKey.substring(0, index);
    }
}
